package de.playmee.enums;

public enum Release {

	UntilSeventies	(0, "Until 70s"),
	Eighties		(1, "80s"),
	Nineties		(2, "90s"),
	From2k			(3, "2000+"),
	LastYear		(4, "Last year"),
	ThisYear		(5, "This year");

	private final int id;
	private final String s;

	private Release(int id, String s) {
		this.id = id;
		this.s = s;
	}

	public int getId() {
		return id;
	}

	@Override
	public String toString() {
		return s;
	}
	
	/**
	 * @return array with all releases
	 */
	public static Release[] getArray() {
		return new Release[] { UntilSeventies, Eighties,
				Nineties, From2k, LastYear, ThisYear };
	}

	/**
	 * returns the release with the given id
	 * 
	 * @param id
	 * @return Release
	 */
	public static Release getById(int id) {
		for (Release r : getArray()) {
			if (id == r.getId())
				return r;
		}
		return null;
	}

	/**
	 * returns the release period the given year is within
	 * 
	 * @param _year
	 * @return Release
	 */
	public static Release getByYear(int _year) {
		java.util.Date date = new java.util.Date();
		if (_year < 1980)
			return UntilSeventies;
		if (_year < 1990)
			return Eighties;
		if (_year < 2000)
			return Nineties;
		if (date.getYear() + 1899 == _year)
			return LastYear;
		if (date.getYear() + 1900 == _year)
			return ThisYear;
		else
			return From2k;
	}

	/**
	 * returns an array with all releases needed for editing channel and track settings
	 * 
	 * @return array
	 */
	public static String[] getStringList() {
		Release[] releases = getArray();
		String[] s = new String[releases.length];
		for (int i = 0; i < releases.length; i++) {
			s[i] = releases[i].toString();
		}
		return s;
	}
}
